package com.wv.api.server.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.util.SaResult;
import com.wv.api.server.common.BaseController;
import com.wv.api.service.ITestService;
import com.wv.common.result.Result;
import com.wv.model.system.Test;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/test")
@Api(tags = "测试相关接口")
@Slf4j
public class TestController extends BaseController {

    @Autowired
    private ITestService testService;

    @GetMapping
    @SaCheckPermission("user:test")
    @ApiOperation(value = "excel导出")
    public SaResult getTest(HttpServletResponse response) {
        ArrayList<Test> tests = new ArrayList<>();
        tests.add(Test.builder().id("1").name("黄达森").birthday(new Date()).gender(1).build());
        outExcel(response,tests,Test.class,"测试");
        return success();
    }

    @PostMapping
    @ApiOperation(value = "excel导入")
    public SaResult setTest(@RequestPart("file") MultipartFile file)     {
        List list = inputExcel(file, Test.class);
        return success(list);
    }


    @PostMapping("exception")
    @ApiOperation(value = "非空验证")
    public String testException(@RequestBody @Validated Test test){
        return "没问题";
    }
//    public Result createFunctionDatasourceAndSwMbqcdss(@Valid Test createReqVO, @RequestParam("file") MultipartFile file) throws IOException, ExecutionException, InterruptedException {
//        long filesize = file.getSize();
//        log.info("导入文件大小：{}k",filesize / 1024);
//        return success(testService.createFunctionDatasourceAndSwMbqcdss(createReqVO,file));
//    }


}
